/**
 * Created by abiu on 2016-05-09.
 */
baseUrl = "http://114.55.33.88:8080/virtualStock";
//baseUrl = "http://127.0.0.1:2111";

describe("login ", function () {
    var configuration = {
        url: baseUrl + "/user/login",//请求的接口
        data: {
            "account": "admin",
            "password": "admin"
        }
    };
    it('login', function (done) {
        function cb( data) {
            expect(data.code).toBe(0);
            done();
        }
        sendRequest(cb, configuration)
    })
})
var listChannel = getApi('/channel/list'),
    modifyChannel = getApi('/channel/modify'),
    createChannel = getApi('/channel/create'),
    removeChannel = getApi('/channel/delete',{code:0,result:{n:1}});
function newChannel(ob) {
    var id = getUniqueId();
    var origin = {
        "channelId": "渠道" + id,
        "channelName": "厦门机场" + id,
        "contactPerson": "联系人",
        "phone": "电话123",
        "address": "地址"
    }
    if (ob) {
        Object.keys(ob).forEach(function (key) {
            origin[key] = ob[key];
        })
    }
    return origin;
}

describe("新增渠道 /channel/create", function () {
    var configuration = {
        url: baseUrl + "/channel/create",
        data: newChannel()
    };
    describe('create  normally ', function () {
        var result = {};
        var channel = newChannel();
         createChannel(function(){return channel},null,function(data){result = data.result});
        listChannel(function(){return channel});
        removeChannel(function(){return {_id:result._id}});
            })
    testRequire(newChannel ,['channelId','channelName'],'/channel/create','/channel/list','/channel/delete');
    testUnique(newChannel,['channelId'],'/channel/create','/channel/list','/channel/delete')


})

describe('修改渠道 /channel/modify',function(){

})

describe('删除渠道 /channel/delete',function(){
    var result;
    var channel = newChannel();
    createChannel(function(){return channel},null,function(data){result = data.result})
    removeChannel(function(){return result})
    listChannel( function(){return channel},{code:0},function(data){expect(data.result.length).toBe(0)})

})